package com.example.classcommunity3.dao;

import com.example.classcommunity3.model.SubmitHomework;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface SubmitHomeworkDao extends JpaRepository<SubmitHomework, Long> {

    List<SubmitHomework> findByHomeworkId(Long hId);

    SubmitHomework findByHomeworkIdAndSStuAccount(Long hId, Long account);

    @Transactional
    @Modifying
    @Query(nativeQuery = true, value = "DELETE FROM submit_homework WHERE homework_id = ?1")
    int deleteByHomeworkId(Long hId);

    @Transactional
    @Modifying
    @Query(nativeQuery = true, value ="DELETE FROM submit_homework WHERE submit_homework.homework_id = ?1 AND submit_homework.s_stu_account = ?2" )
    int deleteByHomeworkIdAndSStuAccount(Long hId, Long account);
}
